@extends('mobile_end.layouts.base')
{{-- content_header --}}

@section('default_style')
@stop

@section('default_container')

<!-- Notifications -->
@include('mobile_end.layouts.notifications')
<!-- ./ notifications -->

    @yield('container')
    <div style="height: 140px;"></div>
    <div id="navbtn" class="footer">
        <ul>
            <li><a href="{{ URL::to('mobile_end/index') }}"><i class="icon-home"></i> 订餐</a></li>
            <li><a href="{{ URL::to('mobile_end/baskets/index') }}"><i class="icon-shopping-cart"></i> 购物车</a></li>
            <li><a href="{{ URL::to('mobile_end/orders/index') }}"><i class="fa fa-hospital-o"></i> 订单</a></li>
            <li><a href="{{ URL::to('mobile_end/accounts/index') }}"><i class="icon-user"></i> 账户</a></li>
        </ul>
    </div>
@stop

@section('default_scripts')
    <script>
        $(function(){
            $('#navbtn').navigator();

            //关闭alert
            $('.alert .close').on('click', function(){
                $(this).parent().remove();
            });
            //设置底部导航栏的激活状态
            var currentUrl = window.location.href;
            $('.footer li').removeClass('ui-state-active');
            $('.footer a').each(function(){
                if($(this).attr('href') == currentUrl){
                    $(this).parent('li').addClass('ui-state-active');
                }
            });
            //添加到购物车按钮事件
            var addFoodToBasketUrl = '{{ URL::action("MobileBasketController@addFoodForJSON") }}';
            $('.button-add-food-to-basket').on('click', function(event){
                var self = $(this);
                var sendData = {
                    _token:'{{{ csrf_token() }}}',
                    id: $(this).attr('data-id'),
                    count:1
                };

                $.ajax({
                    url: addFoodToBasketUrl,
                    type: 'POST',
                    data: sendData,
                    dataType: 'json',
                    success: function(respData){

                        if(respData.result){
                            setTimeout(function(){
                                self.siblings('.show-add-food-msg').animate({
                                    opacity: 0,
                                    bottom: '40px',
                                    background: '#FFFFFF'
                                }, 500, 'ease-out');
                            }, 800);

                            self.siblings('.show-add-food-msg').animate({
                                opacity: 1,
                                bottom: '10px',
                                background: '#99389f'
                            }, 500, 'ease-out');
                        }

                    }});

            });

        });

    </script>
    @yield('scripts')
@stop